<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            height: 100px;
            width: 100px;
            background-color: aquamarine;
        }
    </style>
</head>
<body>
    <div></div>
    <script>
        var boxEle = document.querySelector("div");
        // function bindEvent ( ele , eventName , fn ){
        //     if ( window.addEventListener ){
        //         return ele.addEventListener(eventName,fn);
        //     } else {
        //         return ele.attachEvent("on"+eventName,fn);
        //     }
        // }
        // console.log(bindEvent(document,'keydown',function(){console.log(1111111111);}));
        function bindEvent(ele,eventName,fn){
            // 判断浏览器是否支持 addEventListener方法 
            if(window.addEventListener){
                // 有addEventListener 是chrome浏览器
                ele.addEventListener(eventName,fn);
            }else{
                // ie8或者以下；
                ele.attachEvent("on"+eventName,fn);
            }
        }
        bindEvent(boxEle,"mousedown",function(){
            console.log("鼠标按下了");
        })
    </script>
</body>
</html>